package com.czy.owner.ui.archive;

import android.text.TextUtils;
import android.widget.RelativeLayout;

import com.czy.owner.R;
import com.czy.owner.entity.CarArchiveType;
import com.czy.owner.entity.MaintenanceRecord;
import com.czy.owner.utils.StringUtils;
import com.czy.owner.utils.TimeUtils;
import com.czy.owner.widget.PageTitleView;

/**
 * Created by hedepu on 2017-10-26
 * 修改
 */

public class ArchiveEditActivity extends ArchiveAddActivity {

    @Override
    protected void updateViews() {
        super.updateViews();
        successToast = "编辑记录成功";
        pageTitle = new PageTitleView((RelativeLayout) findViewById(R.id.rl_page_title), "记一笔", true);
        btnAdd.setText("确认编辑");
        MaintenanceRecord maintenance = (MaintenanceRecord) getIntent().getSerializableExtra("maintenance");
        carFilesRecordId = maintenance.getCarFilesRecordId() + "";
        etDate.setText(TimeUtils.timeStamp2Date(maintenance.getServiceTime() + "", "yyyy-MM-dd"));
        etAmount.setText(maintenance.getPrice() + "");
        etMileage.setText(maintenance.getCurrentMileage() + "");
        if ("未设置".equals(maintenance.getNote()) || StringUtils.isEmpty(maintenance.getNote())) {
            etRemark.setText("");
        } else {
            etRemark.setText(maintenance.getNote());
        }

        mArchiveType = new CarArchiveType();
        if (maintenance.getCarFilesCostTypeId() > 0) {
            etType.setText(maintenance.getTypeName());
            interceptLongClick = true;
            etType.setFocusable(false);
            etType.setFocusableInTouchMode(false);

            mArchiveType.setCarFilesCostTypeId(maintenance.getCarFilesCostTypeId());
            mArchiveType.setTypeName(maintenance.getTypeName());
        } else {
            interceptLongClick = false;
            etType.setFocusable(true);
            etType.setFocusableInTouchMode(true);
            etType.requestFocus();
            mArchiveType.setTypeName(TextUtils.isEmpty(maintenance.getTypeName()) ? maintenance.getServiceName() : maintenance.getTypeName());
            etType.setText(mArchiveType.getTypeName());
        }
    }
}
